<template>
	<view style="background-color: #F7F7F7;height: 100vh;">
		<uni-nav-bar left-img="back" title="修改顾客信息"></uni-nav-bar>
		<forms class="guest" :options="options" ></forms>
	</view>
</template>

<script>
	import forms from '@/components/uni-z/forms.vue'

	export default {
		components: { forms },
		data() {
			return {
				options:{}
			}
		},
		onShow(){
			let _this = this;
			_this.handleSugoioLoad('顾客信息', 'guest-form')
		},
		onLoad(e) {
            this.$users.checkLogin();

			var year = new this.XDate().getFullYear();
			this.options = {
				formType:"u",
				title:"顾客信息",
				viewUrl:"customer/id?id=" + e.ID,
				saveUrl:"customer/update",
				columns:[
					{name:"id",text:"id",noShow:true},
					{name:"nickName",text:"昵称"},
					{name:"sex",text:"性别",type:"select",items:[{value:'1',text:'男'},{value:'0',text:'女'}]},
					{name:"birth",text:"出生年份",type:"select",mode:"date",fields:"year",change:(item)=>{
						var ageItem = this.options.columns[4];
						var age = parseInt(new this.XDate(item.value + '-01-01').diffYears(new this.XDate()));
						ageItem.value= (age<0 ? 1 : age);
						this.$set(this.options.columns,4,ageItem);	
					}},
					{name:"age",text:"年龄",type:'text',msg:"岁"},
					{name:"tell",text:"手机号码",mode:"mobile",change:()=>{
						var tell = this.options.columns[5];
						var tellValue = tell.value.replace(/\s+/g, "");
						if(tellValue.length==11){
							var regPhone = (/^(13[0-9]|14[1579]|15[0-3,5-9]|16[6]|17[0123456789]|18[0-9]|19[89])\d{8}$/); //手机号码
							if(!regPhone.test(tellValue)){
							    this.$common.toast("手机号格式错误");
							}
						}
					}},
					{name:"remarks",text:"备注",type:"textarea",noCheck:true,maxlength:100},
				]
			}
		},
		onShow() {
			// 加载埋点
			document.title = '修改顾客信息'
			try {
				window.sugoio.load('guest-form',{})
			} catch (error) {
				console.log('error :>> ', error);
			}
		},
		methods: {
		}
	}
</script>

<style lang="scss" scoped>
	body{
		background-color: #F7F7F7;
	}
	.guest /deep/ .weui-cell:after{
		left: 100px;
	}
	.guest /deep/ .weui-cells:after{
		border: 0px;
	}
	
	.guest /deep/ .weui-bottom:before{
		border: 0px;
		height: 0px;
	}
</style>
